def mountDir()
{
	return '\\\\10.2.72.118\\DistributeProject'
}

def unityRemoteDir()
{
	return "z:\\unity_dsitributed\\Unity.exe"
}


def proposedWorkesPerNode()
{
	return 10
}

def distributeDir()
{
	return ".distribute"
}

def distributeLogDir()
{
	return ".distribute\\log"
}

def root()
{
	return Jenkins.instance.root
}

def rootDir()
{
	return Jenkins.instance.getRootDir()
}

def rootPath()
{
	return Jenkins.instance.getRootPath()
}

def buildName()
{
	return currentBuild.displayName
}

def workSpace()
{
	return "${env.WORKSPACE}\\..\\Z"
}

def fullProjectName()
{
	return currentBuild.fullProjectName
}

def excludeFile()
{
	return "Z:\\config\\copy.exclude"
}

def projectDir(String name)
{
   if(name == 'Test')
   {
      return "z:\\Test_20180418"
   }
   else if(name == 'Chijin')
   {
      return "Z:\\cli\\Res"
   }
}

def mountProjectDir(String name)
{
	if(name == 'Test')
	{
		return "E:\\DistributeProject\\Test_20180418"
	}
	else if(name == 'Chijin')
	{
		return "E:\\DistributeProject\\cli\\Res"
	}
}

def projectName(String name)
{
	File file = new File(projectDir(name))
	return file.name
}

def localProjectDir(String name)
{
	return "${workSpace()}\\${projectName(name)}"
}

def copyProjectToLocal(String name)
{
	def srcProjectDir = projectDir(name)
	def destProjectDir = localProjectDir(name)
    bat "if not exist ${destProjectDir} (mkdir ${destProjectDir})"
    bat "xcopy ${srcProjectDir} ${destProjectDir} /E /Y /D /Q /EXCLUDE:${excludeFile()}"
	return destProjectDir
}

def copyLibraryFilesToLocal(String name)
{
	def srcLibraryDir = "${projectDir(name)}\\Library"
	def destLibraryDir = "${localProjectDir(name)}\\Library"
    bat "if not exist ${destLibraryDir} (mkdir ${destLibraryDir})"
    bat "xcopy ${srcLibraryDir} ${destLibraryDir} /E /Y /D /Q"
}

def prepareLocalProject(String name)
{
	// copyProjectToLocal(name)
	copyLibraryFilesToLocal(name)

	// // TODO. 暂时 ProjectSettings 文件夹，也直接拷贝
	// def srcProjectSettingsDir = "${projectDir(name)}\\ProjectSettings"
	// def destProjectSettingsDir = "${localProjectDir(name)}\\ProjectSettings"
    // bat "if not exist ${destProjectSettingsDir} (mkdir ${destProjectSettingsDir})"
    // bat "xcopy ${srcProjectSettingsDir} ${destProjectSettingsDir} /E /Y /D /Q"

	// // 创建一个空的 Assets，仅仅是为了让 Unity 认为它是一个工程。Unity 源码中，有判断需要有 Assets 文件夹才是 Unity 工程
	// def destAssetsDir = "${localProjectDir(name)}\\Assets"
	// bat "if not exist ${destAssetsDir} (mkdir ${destAssetsDir})"
}

def workesPerNode(int workCount, int nodeCount, int workesPerNodeInParams)
{
	return Math.min( Math.max((int)Math.ceil(workCount / nodeCount), 1), workesPerNodeInParams)
}

def unityDir()
{
	return "${workSpace()}\\Unity" 
}

def localUnityPath()
{
	return "${workSpace()}\\Unity\\Unity.exe" 
}

def copyUnityDir()
{
	def srcDir = "z:\\unity_dsitributed"
	def destDir = "${unityDir()}" 
    bat "if not exist ${destDir} (mkdir ${destDir})"
    bat "xcopy ${srcDir} ${destDir} /E /Y /D /Q"
	return destDir
}

def yamlTest()
{
   def mainfestFile = "E:/DistributeProject/cli/Res/distribute.manifest"
   datas = readYaml (file: "${mainfestFile}")

   echo datas.outputPath
   echo datas.originalOutputPath
   // echo datas.WorkCount
   echo "${datas.WorkCount}"
}


return this